package com.thams.service;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.thams.dao.TestDao;
import com.thams.entity.Test;
import com.thams.service.i.ITestService;
public class TestService extends DataBaseService implements ITestService{

	private static Logger log = Logger.getLogger(TestService.class);
	
	@Autowired
	private TestDao testDao;
	@Override
	public List<Test> test() {
		List<Test> testList = testDao.getTestList();
		for (Test test : testList) {
			System.out.println(test.getTest());
		}
		return testList;
	}
	public void insertTwoTest(){
		try {
			Test t1= new Test();
			t1.setId(1);
			t1.setTest("测试1");
			Test t2= new Test();
			t2.setId(1);
			t2.setTest("测试2");
			testDao.addTest(t1);
			testDao.addTest(t2);
		} catch (Exception e) {
//			throw new RuntimeException("dfdsf");
		}
			
	}
	
	public void initData(){
		if(!existTable("TEST")){
			try {
				//初始化建表
				String initTableSQLFile = TestService.class.getClassLoader().getResource("config/initTable.sql").getFile();
				executeSQL(FileUtils.readFileToString(new File(initTableSQLFile),"utf-8"));
			} catch (IOException e) {
				log.error(e.getMessage());
			}
		}
	}

}
